#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long freq[100005];
long long dp[100005];

int main()
{
	int n;
	cin >> n;

	int mx = -1;
	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin >> tmp;
		freq[tmp]++;

		if (tmp > mx) mx = tmp;
	}

	dp[1] = freq[1];

	if (n >= 2)
	{
		dp[2] = max(dp[1], freq[2] * 2);

		for (int i = 3; i <= mx; ++i)
			dp[i] = max(dp[i - 1], freq[i] * i + dp[i - 2]);
	}
	else
	{
		cout << mx << endl;
		return 0;
	}
	
	cout << dp[mx] << endl;
	
	return 0;
}